<?php

	//前台注册控制器
	class RegisterAction extends Action{
		
		//加载注册页面
		public function add(){
			
			$this->display('register');
		}
		
		
		//会员注册成功
		public function reg(){
			
			 if(isset($_POST['submit'])){				
				$member=D('Member');
				//MD5加密
				$pass=md5($_POST['pass']);
				$_POST['pass']=$pass;
				$member->create();
				if($member->add()){
					$this->success('注册 成功','login');
				}
			} 
			
		}
		
		//前台登录页面
		public function login(){
			$this->display();
		}
		
		
		
			/*
			 *AJAX登录页面验证 
			 * 
			 */	
			public function check_login(){
				//接收用户提交的数据
				$auto=$_POST['auto'];
				//接收数据
				$username=$_POST['name'];
				$password=$_POST['pwd'];			
				$member=D('Member');
				//如果勾选了自动登录
				if($_POST['auto']==1){
					cookie('m_username',$username,'7200');
				}
				//记录每次登录的时间
				$time=time();
				$date=date('YmdH',$time);
				//查看数据库中的数据
				$count=$member->where("m_username='$username' and m_password=md5('$password')")
				->count();
				$data=array('count'=>$count);
				if($count==1){
					$row=$member->where("m_username='$username'")->field('m_id')->find();
					$member->where("m_username='$username'")->save(array(
							'm_status'=>1
				));
					session('m_username',$username);
					session('m_id',$row['m_id']);
				}
			
				
				//返回数据
				$this->ajaxReturn($data,'查询完毕',1);
				
				
			}	
	
		//验证码类
		public function createCapt(){
			import('ORG.Util.Image');
			import('@.Common.Captcha');
			//调用验证码静态方法
			$Captcha=new Captcha();
			$Captcha->generate();
			//Image::buildImageVerify();
		
		}
	}